﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AddFile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!HttpContext.Current.User.Identity.IsAuthenticated || HttpContext.Current.User.Identity.Name!="bogdan")
        {
            Response.Redirect("~/Default.aspx");
        }
        LoadRepeater();
    }

    protected void btnAdauga_Click(object sender, EventArgs e)
    {
        if (upload.HasFile)
        {
            try
            {
                upload.SaveAs(Server.MapPath(".") + "\\download\\" + upload.FileName);
                lblInfo.Visible = true;
                LoadRepeater();
            }
            catch (Exception)
            {
                lblInfo.Visible = false;
                
            }
        }
    }

    private void LoadRepeater()
    {
         System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(Server.MapPath(".") + "\\download");
         System.IO.FileInfo[] fInf0 = directoryInfo.GetFiles();
         repeater.DataSource = fInf0;
         repeater.DataBind();
    }

    protected void lnkSterge_onClick(object sender, EventArgs e) {
        LinkButton lnk = (LinkButton)sender;
        try { System.IO.File.Delete(lnk.CommandArgument); }
        catch (Exception eroare){}
        LoadRepeater();
    }
}
